package ru.rchervot.sanasar.client.view;

import ru.rchervot.sanasar.client.model.UserSettings;
import ru.rchervot.sanasar.client.view.Presenter.Display;

import com.google.gwt.event.shared.HandlerManager;
import com.google.inject.Inject;

public class FactoryModuleSettingsDefault implements FactoryModuleSettings {

	private UserSettings settings;
	private final HandlerManager eventBus;
	
	@Inject
	public FactoryModuleSettingsDefault(HandlerManager eventBus) {
		this.eventBus = eventBus;
	}
	
	
	@Override
	public void setSettings(UserSettings settings) {
		this.settings = settings;
	}
	
	
	@Override
	public Display getViewForPlace() {
		return getModuleView(settings);
	}

	private ModuleSettingsView moduleView;
	private ModuleSettingsView getModuleView(UserSettings settings) {
		if (moduleView == null) {
			moduleView = new ModuleSettingsView();
			
			ModuleSettingsPresenter p = new ModuleSettingsPresenter(
					moduleView, eventBus, settings);
			p.bindDisplay();
		}
		
		return moduleView;
	}
}
